package com.handpay.nocardpay.baselibrary.notification.view.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;

import com.handpay.nocardpay.baselibrary.R;
import com.handpay.nocardpay.baselibrary.account.view.fragment.NoCardLoginFragment;
import com.handpay.nocardpay.baselibrary.commbase.view.activity.BaseActivity;
import com.handpay.nocardpay.baselibrary.logutils.HPLog;
import com.handpay.nocardpay.baselibrary.notification.model.bean.NoticeBody;
import com.handpay.nocardpay.baselibrary.notification.service.NoticeService;
import com.handpay.nocardpay.baselibrary.notification.view.fragment.NoticeDetailFragment;
import com.handpay.nocardpay.baselibrary.notification.view.fragment.NotificationFragment;

/**
 * Created by fplei on 2017/8/20.
 * 由于在service中需要启动详情页，因此这里消息通知单独挂在一个activity上
 */

public class NoticeActivity extends BaseActivity {
    /**
     * 由于启动该activity存在两个入口，在service中需要导航到消息详情页
     */
    public static final String OPEN_TYPE = "openType";
    //当前默认打开消息条目页面
    public static final int showNotificationList = 0;
    //当前默认打开消息详情页面
    public static final int showNotificationDetail = 1;

    @Override
    public void initData() {

    }

    @Override
    public void initView(@Nullable Bundle savedInstanceState) {
        int openType = getIntent().getIntExtra(OPEN_TYPE, showNotificationList);
        HPLog.i(HPLog.LFP_TAG, "NoticeActivity::openType=" + openType);
        NoticeBody noticeBody = (NoticeBody) getIntent().getParcelableExtra(NoticeService.NOTICE_BEAN);
        if (openType == showNotificationDetail) {
            HPLog.i(HPLog.LFP_TAG, "isShowNotice::info=" + noticeBody.toString());
            Bundle bundle = new Bundle();
            bundle.putString(NoticeService.START_WITH, getIntent().getStringExtra(NoticeService.START_WITH));
            bundle.putParcelable(NoticeService.NOTICE_BEAN, noticeBody);
            if (findFragment(NoticeDetailFragment.class) == null) {
                loadRootFragment(R.id.fl_container, NoticeDetailFragment.newInstance(bundle));
            }
            return;
        }
        if (findFragment(NotificationFragment.class) == null) {
            loadRootFragment(R.id.fl_container, NotificationFragment.newInstance());
        }

    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_notice;
    }
}
